#!/bin/bash
usb_port=/dev/ttyUSB0
usb_port2=/dev/ttyUSB3
./../bin/cmux "$usb_port"
at=""
ppp=""
diag=""
port_list=(`ls /dev/ttyGSM*`)
echo ${port_list[*]}
if [ ${#port_list[*]} -ge 4 ];then
	at=${port_list[0]}
	ppp=${port_list[1]}
    diag=${port_list[2]}       
else
    exit "open fail"
fi

if [ ! "$at" = "" ];then
	sed -i "s|dev_port = .*|dev_port = \'$at\'|" ../cfg/at/other.cfg
fi

if [ ! "$ppp" = "" ];then
	sed -i "s|DEVICE=/dev/.*|DEVICE=$ppp|" ../cfg/ppp/air-ppp-on
	sed -i "s|DEVICE=/dev/.*|DEVICE=$ppp|" ../cfg/ppp/air-ppp-off
	sed -i "s|DEVICE=/dev/.*|DEVICE=$ppp|" ../cfg/ppp/air-ppp-status
fi

python2 main.py
exit "$?"
